<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        /* 参考： https://blog.csdn.net/shiyuqiong/article/details/52075490 */
        /* 方案1 绝对定位+margin：auto */
        /* .wrp {
            background-color: #b9b9b9;
            width: 240px;
            position: relative;
            height: 160px;
        }

        .box {
            background-color: #3e8e41;
            width: 200px;
            height: 120px;
            position: absolute;
            left: 0;
            right: 0;
            top: 0;
            bottom: 0;
            margin: auto;
        } */

        /* 方案2：display:table */

        /* .wrp {
            display: table-cell;
            vertical-align: middle;
            background-color: #b9b9b9;
            width: 240px;
            height: 160px;
        }

        .box {
            background-color: #3e8e41;
            width: 200px;
            height: 120px;
            margin: auto;
        } */

        /* 方案3：display:inline-block */

        .wrp {
            vertical-align: middle;
            background-color: #b9b9b9;
            width: 240px;
            height: 160px;
            text-align: center;
        }

        .box {
            background-color: #3e8e41;
            display: inline-block;
        }

        .wrp:after {
            content: '';
            height: 100%;
            display: inline-block;
            vertical-align: middle;
        }
    </style>
</head>

<body>
    <div class="wrp">
        <div class="box">
            居中元素
        </div>
    </div>
</body>

</html>